package Model.Wall;

import DBAccess.DBAccess;
import Model.User;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

public class Wall {

	public ArrayList<Post> postList;

	/**
	 * 
	 * @element-type Post
	 */
	public Post myPost;

	public User myUser;
	public final static int DELETED = 1;
	public final static int NOTDELETED = 0;


	public int getNumMessages(int userID){
		//Initialize to display 0 messages on wall at begining
		int num = 0;
		
		String cmd = "Select COUNT(postid) from walldb where userID ="+userID;
		PreparedStatement ps = null;
		new DBAccess();
		ResultSet rs = null;
		try {
			ps = DBAccess.con.prepareStatement(cmd);
			rs = ps.executeQuery();
			if (rs.next()) {
				num = rs.getInt(1);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		DBAccess.close(ps, rs);
		//Max number of posts on wall is 10;
		if(num>10)
			return 10;
		else
			return num;
	}
	
	
	public void deletePost(int postID) {
		String cmd = "Delete from walldb where postID = "+postID;
		PreparedStatement ps = null;
		new DBAccess();
		try {
			ps = DBAccess.con.prepareStatement(cmd);
			ps.execute();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		DBAccess.close(ps, null);
	}

}